package LC160;

public class Solution1 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {

        if(headA==null||headB==null){
            return null;
        }
        ListNode a=headA;
        while (a!=null){
            ListNode b=headB;
            while (b!=null){
                if(a==b){
                    return a;
                }
                b=b.next;
            }
            a=a.next;
        }
        return null;
    }
}

 class ListNode{
    int val;
    ListNode next;
    ListNode(int x){
        val=x;
        next=null;
    }
}